import math
def Csum(num1, num2):
    return num1 + num2
def Csub(num1, num2):
    return num1 - num2
def Cmulti(num1, num2):
    return num1 * num2
def Cdiv(num1, num2):
    if num2 == 0:
        print("除数不能为0")
        return 0
    return num1 / num2
def logab(a, b):
    if b <= 0 or a <= 0:
        print("输入数不合法！")
        return 0
    return math.log(a, b)
def evaluate_expression(numbers, operators):
    i = 0
    while i < len(operators):
        op = operators[i]
        if op in ('*', '/', 'log'):
            num1 = numbers[i]
            num2 = numbers[i + 1]
            if op == '*':
                result = Cmulti(num1, num2)
            elif op == '/':
                result = Cdiv(num1, num2)
            elif op == 'log':
                result = logab(num1, num2)
            numbers[i] = result
            del numbers[i + 1]
            del operators[i]
        else:
            i += 1
    result = numbers[0]
    for i in range(len(operators)):
        op = operators[i]
        num = numbers[i + 1]
        if op == '+':
            result = Csum(result, num)
        elif op == '-':
            result = Csub(result, num)
    return result
index = 1
flag = True
while flag:
    cul_num = []
    cul_choice = []
    if input("请问：需要复数(1)还是整数(2)运算？\n") == "1":
        while True:
            num1 = complex(input())
            choice1 = input()
            cul_choice.append(choice1)
            cul_num.append(num1)
            if choice1 == "=":
                break
    else:
        while True:
            try:
                num1 = float(input())
                choice1 = input()
                cul_choice.append(choice1)
                cul_num.append(num1)
                if choice1 == "=":
                    break
            except ValueError:
                print("请输入有效数字！")
                continue
    try:
        result = evaluate_expression(cul_num.copy(), cul_choice[:-1].copy())
        print(result)
    except Exception as e:
        print(f"计算错误: {e}")
    conti = input("是否继续？Y/N\n")
    if conti.lower() != 'y':
        flag = False